<?php namespace Summer\Hjd\Controllers;

use Backend\Classes\Controller;
use BackendMenu;
use RainLab\User\Models\User as UserModel;
use Request;

class OrgChart extends Controller
{
    public $implement = [    ];
    
    public function __construct()
    {
        parent::__construct();
        \BackendMenu::setContext('Winter.System', 'main-menu-item-hjd_enduser');
    }


    public function tuijian()
    {
        \Summer\Hub\Classes\SideNavManager::setContext('Summer.Hjd', 'side-menu-item-hjd_orgchart_tuijian');
        $this->vars['info'] = 123;

        $search_text=Request::input('search_text');
        if($search_text){
            $user_info=UserModel::with(['leveluinfo'])->where(['userphone'=>$search_text])->first();
        }
        if(empty($user_info)){//没有搜索显示网头
            $user_info['id']=0;
            $user_info['username']='0000';
            $user_info['userphone']='0000';
            $user_info['realname']='公司';
        }
        $datascource['id']=strval($user_info['id']);//这里要用字符串
        $datascource['name']=$user_info['username'];
        $datascource['title']=$user_info['userphone']."<br>".$user_info['realname'];
        $node_count=UserModel::where(['tuid'=>$user_info['id']])->count();
        if($node_count>0){
            $datascource['relationship']="001";
        }else{
            $datascource['relationship']="000";
        }
        $datascource_json=json_encode($datascource);
        $this->vars['datascource'] = $datascource_json;
        $this->vars['search_text'] = $search_text;
        $this->addCss('/plugins/summer/hub/assets/orgchart/css/jquery.orgchart.css');
        $this->addCss('/plugins/summer/hub/assets/orgchart/css/style.css');
        $this->addJs('/plugins/summer/hub/assets/orgchart/js/jquery.orgchart.js');
    }

}
